﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BDShop.Business;
using BDShop.Business.Cache;
using BDShop.Configuration;
using BDShop.Entities;
using BDShop.Models;
using BDShop.Framework.Web;
using BDShop.Filters;

namespace BDShop.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
           SEOModels seoModels=new SEOModels();
          
            return View(seoModels);
        }

        
        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        #region Child Action Only
        [ChildActionOnly]
        [OutputCache(Duration = 3600)]
        public ActionResult Slider()
        {
            int sliderCount = int.Parse(ConfigCache.Instance.Get().Where(c => c.Key.ToUpper() == BDShopConfiguration.Key.sc.ToUpper()).First().Value);
            var slider = SliderCache.Instance.Get().Where(p => p.IsActive == true).OrderBy(p=>p.Order).Take(sliderCount).ToList<Slider>();
            return PartialView("Partial/_Slider", slider);
        }

        [ChildActionOnly]
        [OutputCache(Duration = 3600)]
        public ActionResult TopMenu()
        {
            //Get parent category 
            List<Category> category = CategoryCache.GetParent(0);

            return PartialView("Partial/_TopMenu", category);
        }

        [ChildActionOnly]
        [OutputCache(Duration = 3600)]
        public ActionResult TopMenuMobile()
        {
            //Get parent category 
            List<Category> category = CategoryCache.GetParent(0);

            return PartialView("Partial/_TopMenuMobile", category);
        }

        [ChildActionOnly]
        public ActionResult MiniCart()
        {
            //Get order from session
            List<OrderDetailModels> lstOrder = SessionHelper.SessionObjects.GetValueOrDefault<List<OrderDetailModels>>("Order");

            if (lstOrder == null)
            {
                lstOrder = new List<OrderDetailModels>();
            }

            return PartialView("Partial/_MiniCart", lstOrder);
        }

        [ChildActionOnly]
        public ActionResult HotTag()
        {
            //Get tag from cache
            List<Tag> lstTag = TagCache.Instance.Get();

            if (lstTag == null)
            {
                lstTag = new List<Tag>();
            }

            return PartialView("Partial/_HotTag", lstTag);
        }

        [ChildActionOnly]
        public ActionResult HotStore()
        {
            //Get supplier from cache
            List<Supplier> lstSupplier = SupplierCache.Instance.Get();

            if (lstSupplier == null)
            {
                lstSupplier = new List<Supplier>();
            }

            return PartialView("Partial/_HotStore", lstSupplier);
        }

        [ChildActionOnly]
        public ActionResult HotBrand()
        {
            //Get brand from cache
            List<Brand> lstBrand = BrandCache.Instance.Get();

            if (lstBrand == null)
            {
                lstBrand = new List<Brand>();
            }

            return PartialView("Partial/_CarouselBrand", lstBrand);
        }
        
        #endregion
    }
}
